package com.meilai.project.controller.web.administration.goods;

import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.entity.administration.goods.GoodsType;
import com.meilai.project.service.administration.goods.GoodsTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("api/web/goods_type")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @GetMapping("/list")
    @ApiOperation("列表")
    public ApiResult<List<GoodsType>> list() {
        return ApiResult.ok(goodsTypeService.list());
    }

    @GetMapping("/list_str")
    @ApiOperation("名称列表")
    public ApiResult<List<String>> list_str() {
        return ApiResult.ok(goodsTypeService.list().stream().map(GoodsType::getName).collect(Collectors.toList()));
    }
}
